package cn.studyjams.s1.contest.autohello.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.studyjams.s1.contest.autohello.model.ColorPicker;
import cn.studyjams.s1.contest.autohello.R;

/**
 * Created by liuyang
 * on 2016/10/6.
 */

public class ColorPickerAdapter extends RecyclerView.Adapter<ColorPickerAdapter.ViewHolder> {

    private List<ColorPicker> mDataset;

    public ColorPickerAdapter(List<ColorPicker> myDataset) {
        mDataset = myDataset;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        // each data item is just a string in this case
        public ImageView previewIV;
        public TextView colorNameTV;

        ViewHolder(View v) {
            super(v);
            previewIV = (ImageView) v.findViewById(R.id.color_preview);
            colorNameTV = (TextView) v.findViewById(R.id.color_name);
        }
    }

    @Override
    public ColorPickerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.color_item, parent, false);
        return new ViewHolder(v);
    }

    // Replace the contents of a view (invoked by the layout manager)
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.previewIV.setImageDrawable(mDataset.get(position).getDrawable());
        holder.colorNameTV.setText(mDataset.get(position).getColorName());
    }

    @Override
    public int getItemCount() {
        return mDataset.size();
    }
}
